
from testunit import assertEqual, assertThrow

import sys, os
os.chdir('..\\controls')
sys.path.append('..\\controls')

from rcontrolutil import *


def main():
	assertEqual( stringToUnderlinePosition('&hello'), ('hello',0))
	assertEqual( stringToUnderlinePosition('hello'), ('hello',-1))
	assertEqual( stringToUnderlinePosition('an &underline'), ('an underline',3))
	assertEqual( stringToUnderlinePosition('two &of&'), ('two of&',4))
	
	assertEqual( underlinePositionToString('two of&',4), 'two &of&')
	assertEqual( underlinePositionToString('hello',-1), 'hello')
	assertEqual( underlinePositionToString('an underline',3),'an &underline')
	
	assertEqual( colorToString('magenta'),'#ff00ff')
	assertEqual( colorToString((200,50,100)),'#c83264')
	assertEqual( stringToColor('#ff00ff'),(255,0,255))
	assertEqual( stringToColor('#c83264'),(200,50,100))
	
	a = BidirectionalDict('this', lambda:{'1':'a', '2':'b','3':'c'})
	assertEqual( a.lookupForward('2'), 'b')
	assertEqual( a.lookupForward('3'), 'c')
	assertEqual( a.lookupReverse('c'), '3')
	assertEqual( a.lookupReverse('b'), '2')
	assertThrow( lambda: a.lookupForward('no'), PyRindPropertyException)
	assertThrow( lambda: a.lookupReverse('non'), PyRindPropertyException)
	
main()
